package com.ruitu.health_1.ui;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.github.jdsjlzx.recyclerview.LRecyclerView;
import com.ruitu.arad.base.base_list.BaseRefreshActivity;
import com.ruitu.arad.base.base_list.ListBaseAdapter;
import com.ruitu.arad.base.base_list.SuperViewHolder;
import com.ruitu.arad.support.widget.progress.ProgressLayout;
import com.ruitu.health_1.R;
import com.ruitu.router_module.bean.cart.CouponList;
import com.ruitu.health_1.mvp.model.UserInfoModel;
import com.ruitu.health_1.mvp.presenter.UserInfoPresent;
import com.ruitu.router_module.AppHolder;

import java.util.List;

public class CouponListActivity extends BaseRefreshActivity<UserInfoPresent.CouponListP, UserInfoModel.CouponListM> {

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_coupon_list;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHeadTitle("我的优惠券");
    }

    private DataAdapter adapter;

    @Override
    protected RecyclerView.Adapter initAdapter() {
        adapter = new DataAdapter(this);
        return adapter;
    }

    @Override
    protected LRecyclerView findRecyclerView() {
        return findViewById(R.id.l_recyclerview);
    }

    @Override
    protected void initViews() {
        super.initViews();
        showProgress();
        getData();
    }

    @Override
    protected void reqFirst() {
        size = 10;
        getData();
    }

    @Override
    protected void reqMore() {
        size = size + 10;
        getData();
    }

    private int size = 10;

    private void getData() {
        p.couponList(1, size, AppHolder.instance().getUser().getId(), "");
    }

    public void setData(List<CouponList> couponList) {
        refreshComplete();
        adapter.setDataList(couponList);
    }

    @Override
    protected ProgressLayout findProgressLayout() {
        return null;
    }

    class DataAdapter extends ListBaseAdapter<CouponList> {

        public DataAdapter(Context context) {
            super(context);
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_coupon;
        }

        @Override
        public void onBindItemHolder(SuperViewHolder holder, int position) {
            TextView tv_name = holder.getView(R.id.tv_name);
            TextView tv_amount = holder.getView(R.id.tv_amount);
            TextView tv_time = holder.getView(R.id.tv_time);
            TextView tv_use = holder.getView(R.id.tv_use);

            CouponList coupon = mDataList.get(position);
            tv_name.setText(coupon.getName());
            tv_amount.setText("￥" + coupon.getPrice());
            tv_time.setText(coupon.getEndTime() + "前有效");
            tv_use.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                }
            });
        }
    }
}
